#include "XiolTime.h"

#include <windows.h>

namespace Xiol
{

unsigned long long int Time::mInitialTickCount = 0xffffffffffffffffLL;

unsigned long long int Time::getTickFrequency()
{
	LARGE_INTEGER frequency;
	QueryPerformanceFrequency(&frequency);
	return frequency.QuadPart;
}

unsigned long long int Time::getTimeAsTicks()
{
	unsigned long long int tickCount;
	LARGE_INTEGER l;
	QueryPerformanceCounter(&l);
	tickCount = l.QuadPart;
	if ( mInitialTickCount==0xffffffffffffffffLL )
		mInitialTickCount = tickCount;
	tickCount -= mInitialTickCount;
	return tickCount;
}

unsigned int Time::getTimeAsMilliseconds()
{
	unsigned int millecondsTime = static_cast<unsigned int>( (getTimeAsTicks() * 1000) / getTickFrequency() );
	return millecondsTime;
}

}